/*
 * config.h
 *
 *  Created on: May 23, 2021
 *      Author: kirk_
 */

#ifndef CONFIG_H_
#define CONFIG_H_
/* Include major head */
#include "main.h"
#include "cmsis_os.h"
/* Include sys lib */
#include "string.h"
#include "stdio.h"
/* Include kdl */
#include "kdl_tb6612.h"
#include "kdl_encoder.h"
#include "kdl_led.h"
#include "kdl_mpu6050.h"
#include "kdl_servo.h"
/* Include kd */
#include "kd_floatpid.h"
#include "kd_math.h"
/* Include hardware */
#include "hcsr04.h"
#include "oled.h"
#include "font.h"
/* Define */
#define PRINTF(fmt, ...)    printf("%s,%d:\t" fmt, __FUNCTION__, __LINE__, ## __VA_ARGS__)
#define Debug 0U

#if Debug
#define CheckHere PRINTF("Here!\r\n")
#else
#define CheckHere (void)0
#endif

#define Mech_Wheel 0

#define Usmart_Huart huart1

#define MPU6050_Addr 0xD0
#define Direction_Erase_Error_Times (256U)
#define Default_Fetch_Period 100U
#define Default_Direction_Period 50U
#define Max_Velocity 400000
#define Movement_Normalize 210
#define Distance_Decrease ((float)0.66)
#define Distance_AdjustTimes     12U
#define Distance_AdjustInterval 100U
#define Distance_AdjustMove     300U
#define Distance_AdjustTurnBound 30U
#define UltraSonic_Distance 136U

#define Enable_Direction_PID 1
#define Enable_Position_PID 1

extern KDL_TB6612_t Motor[4];
extern KDL_Encoder_t Encoder[4];
extern KDL_MPU6050_t MPU6050;
extern KDL_Servo_t Servo[4];
extern HCSR04_t HCSR04[3];

extern KD_FloatPID_t Velocity[4];
#if Mech_Wheel
extern KD_FloatPID_t PositionX;
extern KD_FloatPID_t PositionY;
#endif
#if 0
extern KD_FloatPID_t PositionL;
extern KD_FloatPID_t PositionR;
//extern KD_FloatPID_t Position;
#endif

extern KD_FloatPID_t PositionX;
extern KD_FloatPID_t Direction;

/* Handler external */
extern I2C_HandleTypeDef hi2c1;
extern I2C_HandleTypeDef hi2c2;

extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim3;
extern TIM_HandleTypeDef htim5;
extern TIM_HandleTypeDef htim8;
extern TIM_HandleTypeDef htim15;

extern UART_HandleTypeDef huart1;

/* Thread external */
extern osThreadId_t DefaultThreadHandle;
extern osThreadId_t BeatLightThreadHandle;
extern osThreadId_t UsmartThreadHandle;
extern osThreadId_t AdjustThreadHandle;
extern osThreadId_t DirectionThreadHandle;
extern osThreadId_t DistanceThreadHandle;

extern osThreadId_t Patio1TaskHandle;
extern osThreadId_t Patio2TaskHandle;
/* Timer external */
extern osTimerId_t AdjustTimerHandle;
extern osTimerId_t DistanceTimerHandle;
extern osTimerId_t DirectionTimerHandle;

/* Exported function */
void print_team(void);

#endif /* CONFIG_H_ */
